<?php
/**
 * @author GhostWei
 * @date Sep 13, 2012
 */
class controller_admin_collection_list extends system_user_controller_panel {
	
	private $concept = null;
	public function init() {
		if(!parent::init()) {
			return ;
		}
		$this->concept = new collection_error_concept($this->user->getLang());
		$this->_crumbs()->addPage(system_nav_page::create($this->language('Collections'))->setRoute('collection/index'));
		$this->_crumbs()->addPage(system_nav_page::create($this->language('Lists'))->setRoute('collection/list/index'));
	}
	
	public function action_error() {
		$this->_batchDelete($this->concept, 'id', 'id');
		$adapter = new system_paginator_adapter_concept($this->concept);
		$adapter->setCurrentPageNumber(intval($this->getRequest()->getParam('page', 1)));
		
		$this->view->order = $order = strtolower($this->_get('order'));
		$keyword = trim($this->_get('keyword'));
		if($keyword == self::$_keyword) $keyword = '';
		if($keyword) {
			$adapter->where("`message` LIKE ? OR `params` LIKE ? OR link.`url` LIKE ?", "%$keyword%");
		}
		$_order = array("error.id DESC");
		if($order) {
			$this->view->sort = $sort = intval($this->_get('sort'));
			switch($order) {
				case 'date': {
					$order = 'creationtime';
					break;
				}
				default: {
					$sort = !$sort;
					$order = 'id';
					break;
				}
			}
			$_sort = !$sort ? 'DESC' : 'ASC';
			$_order = array("$order $_sort");
		}
		$adapter->setLimit(30);
		$adapter->order($_order);
		$this->view->list = new system_paginator($adapter);;

		$this->_crumbs()->addPage(system_nav_page::create($this->language('Error Logs'))->setRoute('collection/list/error'));
		$this->render();
	}
	
	public function action_index() {
		$this->render();
	}
	
}
